<template>
  <div>
    <SkuDetail ref="SkuDetail" class="array" />
    <el-card shadow="never" class="card">
      <div slot="header" class="clearfix">
        <el-button type="primary" size="default" @click="add"
          >新增文章</el-button
        >
      </div>
      <el-table :data="homeInfo" style="width: 100%" max-height="1000" border>
        <el-table-column fixed type="index" width="50" label="序号">
        </el-table-column>
        <el-table-column
          prop="province"
          label="广告图片"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <img
              style="width: 100px; height: 100px"
              :src="scope.row.pic"
              alt=""
            />
          </template>
        </el-table-column>

        <el-table-column label="活动时间" width="300" align="center">
          <template slot-scope="scope">
            <div>开始时间： {{ scope.row.createTime }}</div>
            <div>结束时间： {{ scope.row.endTime }}</div>
          </template>
        </el-table-column>
        <el-table-column
          width="150"
          label="广告名称"
          prop="name"
          align="center"
        >
        </el-table-column>
        <el-table-column
          width="150"
          label="点击数"
          prop="clickCount"
          align="center"
        >
        </el-table-column>
        <el-table-column
          width="150"
          label="下单数"
          prop="orderCount"
          align="center"
        >
        </el-table-column>

        <el-table-column width="150" label="轮播位置" align="center">
          首次轮播
        </el-table-column>

        <el-table-column width="150" label="备注" prop="note" align="center">
        </el-table-column>
        <el-table-column
          width="150"
          label="上下线状态"
          prop="orderCount"
          align="center"
        >
          上线
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template slot-scope="scope">
            <el-button
              @click="compile(scope.row)"
              type="text"
              size="small"
              style="color: red !important"
            >
              编辑
            </el-button>
            <el-button
              @click="deleteRow(scope.row)"
              type="text"
              size="small"
              style="color: red !important"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import marketing from '@/api/marketing'
import SkuDetail from './components/SkuDetail.vue'
export default {
  components: {
    SkuDetail,
  },
  data() {
    return {
      homeInfo: [],
    }
  },
  created() {},
  mounted() {
    this.adsListApi()
  },
  methods: {
    adsListApi() {
      marketing.adsListApi().then(res => {
        this.homeInfo = res.data.items
        console.log(this.homeInfo, 'this.homeInfo')
      })
    },
    //新增广告
    add() {
      console.log('新增广告')
      this.$refs.SkuDetail.open()
    },
    //编辑广告
    compile(row) {
      console.log(row, '编辑')
      this.$refs.SkuDetail.open(row)
    },
    //删除文章
    deleteRow(row) {
      //删除广告
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        marketing.delAdsApis(row.id).then(res => {
          if (res.success) {
            console.log(res, 'resss')
            this.$message.success('删除成功')
            this.adsListApi()
          } else {
            this.$message.error(res.message)
          }
        })
      })
    },
  },
}
</script>

<style>
</style>